export const state = () => ({
  token: "",
  userInfo: ""
});

export const mutations = {
  setToken(state, val) {
    state.token = val;
  },   
  setUserInfo(state, val) {
    state.userInfo = val;
  }
};
export const getters = {
  getToken(state): string {
    return state.token;
  },
  getUserInfo(state): string {
    return state.userInfo;
  }
};

export const actions = {
  GETUSERINFO({ commit }) {
    const _this: any = this;
    const { $axios } = _this;
    return new Promise((resolve, reject) => {
      $axios.$post("/new/userInfo").then(resUser => {
        const resultUser = resUser.data;
        if (resUser && resultUser) {
          resolve(resultUser);
          commit("setUserInfo", resultUser);
        } else {
          reject(null);
        }
      });
    });
  },
};
